package com.vca.front.controller;


import com.vca.common.page.CommonPage;
import com.vca.common.request.PageParamRequest;
import com.vca.common.response.LineUpResponse;
import com.vca.common.result.CommonResult;
import com.vca.service.service.VcaLineUpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 排队登记表 前端控制器
 * </p>
 *
 * @author chenBing
 * @since 2022-11-24
 */
@Slf4j
@RestController("VcaLineUpController")
@RequestMapping("api/front/line/up")
@Api(tags = "候补名单")
public class VcaLineUpController {
    @Autowired
    private VcaLineUpService vcaLineUpService;

    /**
     * @Description:排队登记
     * @Author: chenBing
     * @Date: 2022/11/24
     */
    @ApiOperation(value = "排队登记")
    @RequestMapping(value = "/line/up", method = RequestMethod.POST)
    public CommonResult<String> lineUp(
            @ApiParam(value = "课程/套课/讲座/展览主键id")
            @RequestParam(value = "mainId") Long mainId,
            @ApiParam(value = "类型 0=课程 1=套课 2=讲座 3=展览")
            @RequestParam(value = "type") Integer type
    ) {
        if (vcaLineUpService.lineUp(mainId, type)) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    /**
     * @Description:移除排队记录
     * @Author: chenBing
     * @Date: 2022/11/25
     */
    @ApiOperation(value = "移除排队记录")
    @GetMapping(value = "/remove")
    public CommonResult<String> remove(
            @RequestParam(value = "lineUpId") Integer lineUpId
    ) {
        if (vcaLineUpService.removeLineUpById(lineUpId)) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    /**
     * @Description:候补名单列表
     * @author:chenbing
     * @date 2022/12/21 16:06
     */
    @ApiOperation(value = "候补名单列表")
    @GetMapping(value = "/list")
    public CommonResult<CommonPage<LineUpResponse>> list(
            @RequestHeader(value = "language",required = false) String language,
            @Validated PageParamRequest pageParamRequest
    ) {
        return CommonResult.success(CommonPage.restPage(vcaLineUpService.getList(language,pageParamRequest)));
    }

    /**
     * @Description:不在显示
     * @author:chenbing
     * @date 2022/12/21 17:27
     */
    @ApiOperation(value = "不在显示")
    @GetMapping(value = "/disable")
    public CommonResult<String> disable(
            @RequestParam(value = "lineUpId") Integer lineUpId
    ) {
        if (vcaLineUpService.disable(lineUpId)) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
}

